home *** CD-ROM | disk | FTP | other *** search
/ CD BIT 75 / CD BIT 75.iso / Software / mysql-4.0.22-win / data1.cab / Development / sql-bench / run-all-tests < prev    next >
Encoding:
Text File  |  2004-10-28  |  7.0 KB  |  310 lines

  1. #!/usr/bin/perl
  2. # Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Library General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. # Library General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Library General Public
  15. # License along with this library; if not, write to the Free
  16. # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  17. # MA 02111-1307, USA
  18. #
  19. # This program runs all test that starts with 'test-' and sums
  20. # the results that the program prints.
  21. # Each time result should be of the form:
  22. # Time for|to KEYWORD (number_of_runs) 'other info': timestr()
  23. #
  24. # All options to this script is passed to all test program.
  25. # useful options:
  26. # --fast --force --lock-tables
  27. # --server   ==> mysql (default) / mSQL / Pg (postgres) / Solid
  28. # --user     ==> the user with permission to create / drop / select
  29. # --pass     ==> password for the user
  30. # --cmp      ==> Compare --server with one of the others (mysql/mSQL/Pg/Solid)
  31. # --comments ==> everything you want to say such as the extra options you
  32. #                gave to the db server. (use --comments="xxx xxx xxx"
  33. # --machine  ==> Give a OS/machine id for your logfiles.
  34. # --log         ==> puts output in output/RUN-server-machine-cmp-$opt_cmp
  35.  
  36. use DBI;
  37. use Cwd;
  38.  
  39. $opt_silent=1;            # Don't write header
  40.  
  41. @ORG_ARGV=@ARGV;
  42. $pwd = cwd(); $pwd = "." if ($pwd eq '');
  43. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  44. $opt_silent=0;
  45. $perl=$^X;
  46. $machine=machine();
  47. $redirect= !($machine =~ /windows/i || $machine =~ "^NT\s") ? "2>&1" : "";
  48. $dir= ($pwd =~ /\\/) ? '\\' : '/';    # directory symbol for shell
  49.  
  50. $prog_args="";
  51. foreach $arg (@ORG_ARGV)
  52. {
  53.   if ($redirect)
  54.   {
  55.     $prog_args.="'" . $arg . "' ";
  56.   }
  57.   else
  58.   {
  59.     # Windows/NT can't handle ' around arguments
  60.     $prog_args.=$arg . " ";    
  61.   }
  62. }
  63.  
  64. $prog_count=$errors=0;
  65.  
  66. if ($opt_cmp) {
  67.     $filename = "$opt_server$opt_suffix-" . machine_part() . "-cmp-$opt_cmp";
  68. } else {
  69.     $filename = "$opt_server$opt_suffix-" . machine_part();
  70. }
  71.  
  72. if (! -d $opt_dir)
  73. {
  74.   if (-e $opt_dir)
  75.   {
  76.     die "$opt_dir isn't a directory\n";
  77.   }
  78.   mkdir $opt_dir,0777 || die "Can't create directory: $opt_dir\n";
  79. }
  80.  
  81. if ($opt_skip_test) {
  82.   (@skip_tests) = split(/,\s*/, $opt_skip_test);
  83. }
  84.  
  85. if ($opt_old_headers)
  86. {
  87.   read_headers("$opt_dir/RUN-$filename");
  88. }
  89. else
  90. {
  91.   $server_version=$server->version();
  92. }
  93.  
  94. if (!$opt_log)
  95. {
  96.   open(LOG,">&STDOUT");
  97. }
  98. else
  99. {
  100.   open(LOG, "> $opt_dir/RUN-$filename") ||
  101.     die "Can't write to $opt_dir/RUN-$filename: $!\n";
  102. }
  103.  
  104. select(LOG);
  105. $|=1;
  106.  
  107. print "Benchmark DBD suite: $benchmark_version\n";
  108. print "Date of test:        $date\n";
  109. print "Running tests on:    $machine\n";
  110. print "Arguments:           $log_prog_args\n";
  111. print "Comments:            $opt_comments\n";
  112. print "Limits from:         $opt_cmp\n";
  113. print "Server version:      $server_version\n";
  114. print "Optimization:        $opt_optimization\n";
  115. print "Hardware:            $opt_hw\n\n";
  116.  
  117.  
  118. $estimated=$warning=$got_warning=0;
  119. while (<test-*>)
  120. {
  121.   next if (/\.sh$/);        # configure script
  122.   next if (/\-fork$/);        # test script
  123.   $prog_count++;
  124.   /test-(.*)$/;            # Remove test from name
  125.   $prog=$1;
  126.   $skip_prog = 0;
  127.   foreach $skip_this (@skip_tests) {
  128.     if ($prog =~ /$skip_this/i) {
  129.       $skip_prog = 1;
  130.       last;
  131.     }
  132.   }
  133.   print "$prog: ";
  134.   if ((!$opt_use_old_results) && (!$skip_prog))
  135.   {
  136.     if (system("$perl ./test-$prog $prog_args > \"$opt_dir$dir$prog-$filename\" $redirect"))
  137.     {
  138.       printf STDERR "Warning: Can't execute $prog.  Check the file '$opt_dir$dir$prog-$filename'\n";
  139.       die "aborted" if ($opt_die_on_errors);
  140.     }
  141.   }
  142.   open(TEST,"$opt_dir/$prog-$filename");
  143.   $last_line="";
  144.   while(<TEST>)
  145.   {
  146.     chomp;
  147.     $last_line=$_ if (!(/^\s*$/));        # Search after last line
  148.   }
  149.   if ($last_line =~ /Total time:/i)
  150.   {
  151.     print $last_line . "\n";
  152.     open(TEST,"$opt_dir/$prog-$filename");
  153.     while (<TEST>)
  154.     {
  155.       if (/^(estimated |)time (to|for) ([^\s:]*)\s*\((\d*)(:\d*)*\)[^:]*:\s*([\d.]+) .*secs \(\s*([^\s]*) usr\s*\+*\s*([^\s]*) sys.*=\s+([\d.]*)\s+cpu/i)
  156.       {
  157.     $arg=$summa{$3};
  158.     if (!defined($arg))
  159.     {
  160.       $summa{$3}= [ $4,$6,$7,$8,$9,""];
  161.     }
  162.     else
  163.     {
  164.       $arg->[0]+=$4;
  165.       $arg->[1]+=$6;
  166.       $arg->[2]+=$7;
  167.       $arg->[3]+=$8;
  168.       $arg->[4]+=$9;
  169.     }
  170.     $prog_sum[0]+=$4;
  171.     $prog_sum[1]+=$6;
  172.     $prog_sum[2]+=$7;
  173.     $prog_sum[3]+=$8;
  174.     $prog_sum[4]+=$9;
  175.     if (length($1))
  176.     {
  177.       $summa{$3}->[5].="+";
  178.       $estimated=1;
  179.     }
  180.     if ($got_warning)
  181.     {
  182.       $summa{$3}->[5].="?";
  183.       $warning=1;
  184.       $got_warning=0;
  185.     }
  186.       }
  187.       elsif (/^warning/i)
  188.       {
  189.     $got_warning=1;
  190.       }
  191.       else
  192.       {
  193.     $got_warning=0;
  194.       }
  195.     }
  196.     if ($opt_debug)
  197.     {
  198.       print "Summary for $prog: ", join(" ",@prog_sum), "\n";
  199.     }
  200.   }
  201.   elsif ($last_line =~ /^Test skipped/i)
  202.   {
  203.     print "$last_line\n";
  204.   }
  205.   else
  206.   {
  207.     $errors++;
  208.     print "Failed ($opt_dir/$prog-$filename)\n";
  209.   }
  210. }
  211.  
  212. print "\n";
  213. if (!$errors)
  214. {
  215.   print "All $prog_count test executed successfully\n";
  216. }
  217. else
  218. {
  219.   print "Of $prog_count tests, $errors tests didn't work\n";
  220. }
  221. if ($estimated)
  222. {
  223.   print "Tests with estimated time have a + at end of line\n"
  224. }
  225. if ($warning)
  226. {
  227.   print "Tests with didn't return the correct result have a ? at end of line\n";
  228. }
  229.  
  230. if (%summa)
  231. {
  232.   @total=(0,0,0,0,0,"");
  233.   print "\nTotals per operation:\n";
  234.   print "Operation             seconds     usr     sys     cpu   tests\n";
  235.   foreach $key (sort(keys %summa))
  236.   {
  237.     $arg=$summa{$key};
  238.     printf("%-35.35s %7.2f %7.2f %7.2f %7.2f %7d %s\n",
  239.        $key,$arg->[1],$arg->[2],$arg->[3],$arg->[4],$arg->[0],
  240.        $arg->[5]);
  241.  
  242.     for ($i=0 ; $i < 5 ; $i++)
  243.     {
  244.       $total[$i]+=$arg->[$i];
  245.     }
  246.     $total[5].=$arg->[$i];
  247.   }
  248.   printf("%-35.35s %7.2f %7.2f %7.2f %7.2f %7d %s\n",
  249.      "TOTALS",$total[1],$total[2],$total[3],$total[4],$total[0],
  250.      $total[5]);
  251. }
  252.  
  253. select(STDOUT);
  254. if ($opt_log)
  255. {
  256.   print "Test finished. You can find the result in:\n$opt_dir/RUN-$filename\n";
  257. }
  258.  
  259.  
  260. #
  261. # Read headers from an old benchmark run
  262. #
  263.  
  264. sub read_headers
  265. {
  266.   my ($filename)=@_;
  267.  
  268.   # Clear current values
  269.   $benchmark_version=$date=$machine=$server_version="";
  270.  
  271.   open(TMP, "<$filename") || die "Can't open $filename\n";
  272.   while (<TMP>)
  273.   {
  274.     chop;
  275.     if (/^Benchmark DBD.*:\s+(.*)$/)
  276.     {
  277.       $benchmark_version=$1;
  278.     }
  279.     elsif (/^Date of.*:\s+(.*)/)
  280.     {
  281.       $date=$1;
  282.     }
  283.     elsif (/^Running.*:\s+(.*)$/)
  284.     {
  285.       $machine=$1;
  286.     }
  287.     elsif (/^Arguments.*:\s+(.*)$/)
  288.     {
  289.       $log_prog_args=$1;
  290.     }
  291.     elsif (/^Limits.*:\s+(.*)$/)
  292.     {
  293.       $opt_cmp=$1;
  294.     }
  295.     elsif (/^Server ver.*:\s+(.*)$/)
  296.     {
  297.       $server_version=$1;
  298.     }
  299.     elsif (/^Optimiz.*:\s+(.*)$/)
  300.     {
  301.       $opt_optimization=$1;
  302.     }
  303.     elsif (/^Hardwar.*:\s+(.*)$/)
  304.     {
  305.       $opt_hw=$1;
  306.     }
  307.   }
  308.   close(TMP);
  309. }
  310.